/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package utillity.view;

import java.awt.Color;
import java.awt.Graphics;
import java.sql.SQLException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
import model.EventLine;
import model.ProductLine;
import model.TicketLine;
import utillity.DateFormatTools;
import utillity.Line;
import static utillity.PrintHandler.LINES_PER_PAGE;
import utillity.StatistikHandler;

/**
 *
 * @author MarcoPc
 */
public class StatestikView extends javax.swing.JPanel {

    private String date;
    private DateFormatTools dateTools;
    private StatistikHandler statistikHandler;
    public static final int LINES_PER_PAGE = 23;
    private ArrayList<Line> lines;
    private static StatestikView statestikView;
    private int xCord;

    /**
     * Creates new form StatestikView
     */
    private StatestikView() throws ParseException {
        try {
            statistikHandler = StatistikHandler.getStatistikHandler();
            initComponents();
            setSize(780, 480);

        } catch (SQLException ex) {
            Logger.getLogger(StatestikView.class.getName()).log(Level.SEVERE, null, ex);
        }
        xCord = 10;

    }

    public static StatestikView getStatView() throws ParseException {
        if (statestikView == null) {
            statestikView = new StatestikView();
        }
        return statestikView;
    }

    public void setStat(ArrayList<Line> lineList, String date) {
        this.lines = lineList;
        this.date = date;
        statestikView.repaint();
        
        
    }

    public void drawLines(Graphics g, int page) {
        dateTools = new DateFormatTools();
        Calendar c = dateTools.getDateFromString(date);
        c = dateTools.getNextday(c, 6);

        g.setColor(Color.BLACK);
        g.drawRect(10, 10, 760, 375);
        g.drawLine(10, 70, 770, 70);
        g.drawLine(10, 120, 770, 120);
        g.drawLine(10, 170, 770, 170);
        g.drawLine(10, 220, 770, 220);
        g.drawLine(10, 270, 770, 270);
        g.drawLine(10, 320, 770, 320);

        g.drawLine(130, 10, 130, 385);
        g.drawLine(220, 10, 220, 385);
        g.drawLine(310, 10, 310, 385);
        g.drawLine(400, 10, 400, 385);
        g.drawLine(490, 10, 490, 385);
        g.drawLine(580, 10, 580, 385);
        g.drawLine(670, 10, 670, 385);

        g.drawString(dateTools.getDay(date), 15, 30);
        g.drawString("Til", 15, 45);
        g.drawString(dateTools.getDay(dateTools.getDateFromCal(c)), 15, 60);
        g.drawString("Voksne", 15, (50 + 50));
        g.drawString("Børn", 15, 150);
        g.drawString("Gratister", 15, 200);
        g.drawString("Omvisninger", 15, 250);
        g.drawString("Omvisninger i pers", 15, 300);
        g.drawString("Antal i Alt", 15, 360);
        

        for (int i = 0; i < lines.size(); i++) {
            g.drawString(dateTools.getDayLetter(lines.get(i).getTicketDate()), (140 + (i * 90)), 40);
            int number = lines.get(i).getTkAdultQu() + lines.get(i).getTkAGroupQu();
            g.drawString("" + number, (170 + (i * 90)), 100);
            g.drawString("" + lines.get(i).getTkKidsQu(), (170 + (i * 90)), 150);
            g.drawString("" + lines.get(i).getTkFreeQu(), (170 + (i * 90)), 200);
            g.drawString("" + lines.get(i).getEvSold(), (170 + (i * 90)), 250);
            g.drawString("" + lines.get(i).getEvQuantities(), (170 + (i * 90)), 300);
            int total = number + lines.get(i).getTkKidsQu() + lines.get(i).getTkFreeQu() + lines.get(i).getEvSold() + lines.get(i).getEvQuantities();
            g.drawString("" + total, (170 + (i * 90)), 360);

        }

    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel(){
            public void paint(Graphics g){
                super.paint(g);
                drawLines(g,0);
            }
        };

        jPanel1.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 700, Short.MAX_VALUE)
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 450, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
    }// </editor-fold>//GEN-END:initComponents


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel jPanel1;
    // End of variables declaration//GEN-END:variables
}
